package com.hinnotek.warehouse.ui

import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.hinnotek.warehouse.BR
import com.hinnotek.warehouse.R
import com.hinnotek.warehouse.bean.MenuBean
import com.hinnotek.warehouse.databinding.ActivityWarehouseBinding
import com.hinnotek.warehouse.databinding.ItemWarehouseMenuBinding
import com.lee.common.adapter.binding.SimpleBindingAdapter
import com.lee.common.base.BaseActivity
import com.lee.common.data.AppDatabase
import com.lee.common.utils.*
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber


/**
 * 仓管主页面
 */
@Route(path = ACTIVITY_WAREHOUSE_MAIN)
@AndroidEntryPoint
class WarehouseActivity : BaseActivity<ActivityWarehouseBinding>() {

    private lateinit var adapter: SimpleBindingAdapter<MenuBean, ItemWarehouseMenuBinding>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_warehouse)
        setTitle("仓库管理")
    }

    override fun initVew() {
        val token = AppDatabase.getInstance(this).userDao().getUser()?.token ?: ""
        Timber.e("token:$token")
        adapter = SimpleBindingAdapter(R.layout.item_warehouse_menu, ArrayList(), BR.warehouseMenu)
        bindingView.mainRecycler.layoutManager = object : GridLayoutManager(this, 3) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        bindingView.mainRecycler.adapter = adapter
        adapter.setNewInstance(MenuBean.getData())
        adapter.setOnItemClickListener { adapter, itemView, position ->
            when (this.adapter.data[position].title) {
                "仓管" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_MAIN)
                }
                "盘库管理" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_QUERY)
                }
                "台账汇总" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_MACHINE_ACCOUNT)
                }
                "仓管入库" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_STOCK_IN)
                }
                "报损" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_LOSS_REPORT)
                }
                "借用" -> {
                    Skipping.start(ACTIVITY_NONCE_BORROWING)
                }
                "设备使用情况" -> {
                    Skipping.start(ACTIVITY_DEVICE_USAGE_QUERY)
                }
                "供应商" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_SUPPLIER_INFO)
                }
                "出库" -> {
                    Skipping.start(ACTIVITY_WAREHOUSE_STOCK_OUT)
                }
                "旧版" -> {
                    Skipping.start(ACTIVITY_MAIN_OLD)
                }
                "预出库" -> {
                    Skipping.start(ACTIVITY_PRE_EX_WAREHOUSE)
                }
            }
        }

    }

    override fun setData() {

    }

}